package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.Section;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface SectionMapper {
    @Insert({"insert into section (project_no,tender_id,section_name,budget,section_time) values (#{projectNo},#{tenderId},#{sectionName},#{budget},#{sectionTime}) "})
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int add(Section section);

    @Select({"<script>", "select s.*,p.name as project_name from section s left join project p on p.project_no = s.project_no <where><if test='projectNo != null and projectNo.length &gt; 0'>and s.project_no = #{projectNo} </if><if test='tenderId != null and tenderId != 0'>and s.tender_id = #{tenderId} </if><if test='assectStatus != null and assectStatus.length &gt; 0'>and s.assect_status = #{assectStatus} </if></where></script>"})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "tenderId", column = "tender_id"), @Result(property = "sectionName", column = "section_name"), @Result(property = "sectionTime", column = "section_time"), @Result(property = "assectStatus", column = "assect_status")})
    List<Section> findAll(Section section);

    @Select({"select s.*,p.name as project_name from section s left join project p on p.project_no = s.project_no where s.id = #{id} "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "tenderId", column = "tender_id"), @Result(property = "sectionName", column = "section_name"), @Result(property = "sectionTime", column = "section_time"), @Result(property = "assectStatus", column = "assect_status")})
    Section selectById(Integer num);

    @Update({"update section set project_no = #{projectNo}, tender_id = #{tenderId}, section_name=#{sectionName}, budget=#{budget}, section_time=#{sectionTime} where id = #{id} "})
    int update(Section section);

    @Delete({"delete from section where id = #{id} "})
    int delete(Integer num);

    @Update({"update section set assect_status = #{assectStatus} where id = #{id} "})
    int assect(Section section);

    @Delete({"delete from section where tender_id = #{tenderId} "})
    int remove(Integer num);

    @Select({"<script>", "select s.*,p.name as project_name,c.type,c.name AS categoryName from ( select fs.* FROM final_statement fs left join processrecord pr ON fs.id = pr.project_id where pr.process_name = 'final_statement' and pr.status = 2 and fs.asset_new_status = 0 ) fs left join section s on s.id = fs.section_id left join project p on p.project_no = s.project_noleft join category c on p.category = c.id <where><if test='projectName != null and projectName.length &gt; 0'>and p.name = #{projectName} </if><if test='sectionName != null and sectionName.length &gt; 0'>and s.section_name = #{sectionName} </if></where>GROUP BY s.id ORDER BY s.id DESC </script>"})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "tenderId", column = "tender_id"), @Result(property = "sectionName", column = "section_name"), @Result(property = "sectionTime", column = "section_time"), @Result(property = "assectStatus", column = "assect_status"), @Result(property = "categoryName", column = "categoryName")})
    List<Map> getAddAssect(Section section);

    @Select({"select * from section where project_no = #{projectNo} "})
    @Results({@Result(property = "sectionName", column = "section_name")})
    List<Section> selectProjectNo(@Param("projectNo") String str);

    @Select({"<script>" +
            "select section_name from section " +
            "<where>  " +
            "id in <foreach collection='ids' item='item' index='index' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach>" +
            "</where>  " +
            "</script>"})
    List<String> findByIds(@Param("ids") String[] strArr);
}